#include "peditor_ccnode.h"
#include "ui_peditor_ccnode.h"
#include "CCQTSceneDirector.h"


PEditor_CCNode::PEditor_CCNode(QWidget *parent) :
    AbstractPEditor(parent),
    ui(new Ui::PEditor_CCNode)
{
	init();
    ui->setupUi(this);
    QMetaObject::connectSlotsByName(this);
    m_doubleSpinBox_x = qFindChild<QDoubleSpinBox *>(this,  "doubleSpinBox_x");
	m_doubleSpinBox_2_y = qFindChild<QDoubleSpinBox *>(this,  "doubleSpinBox_2_y");
	m_doubleSpinBox_3_scaleX = qFindChild<QDoubleSpinBox *>(this,  "doubleSpinBox_3_scaleX");
	m_doubleSpinBox_4_scaleY = qFindChild<QDoubleSpinBox *>(this,  "doubleSpinBox_4_scaleY");
	m_doubleSpinBox_5_rotate = qFindChild<QDoubleSpinBox *>(this,  "doubleSpinBox_5_rotate");
    
    disableAll();
}


QString PEditor_CCNode::regName()
{
	return "CCNode";
}


void PEditor_CCNode::disableAll ()
{
    m_doubleSpinBox_x->setEnabled(false);
    m_doubleSpinBox_2_y->setEnabled(false);
    m_doubleSpinBox_3_scaleX->setEnabled(false);
    m_doubleSpinBox_4_scaleY->setEnabled(false);
    m_doubleSpinBox_5_rotate->setEnabled(false);
}

void PEditor_CCNode::enableAll()
{
    m_doubleSpinBox_x->setEnabled(true);
    m_doubleSpinBox_2_y->setEnabled(true);
    m_doubleSpinBox_3_scaleX->setEnabled(true);
    m_doubleSpinBox_4_scaleY->setEnabled(true);
    m_doubleSpinBox_5_rotate->setEnabled(true);
}

void PEditor_CCNode::checkNode(const QCocoNode & pNode)
{
    QCocoNode * qNode = CCQTSceneDirector::sharedSceneDirector()->CurrentQNode();
    if (qNode == NULL)
    {
        this->disableAll();
    }
    else 
    {
		CCNode * node = qNode->m_node;
        this->enableAll();
        m_doubleSpinBox_x->setValue(node->getPositionX());
        m_doubleSpinBox_2_y->setValue(node->getPositionY());
        m_doubleSpinBox_3_scaleX->setValue(node->getScaleX());
        m_doubleSpinBox_4_scaleY->setValue(node->getScaleY());
        m_doubleSpinBox_5_rotate->setValue(node->getRotation());
    }
}


PEditor_CCNode::~PEditor_CCNode()
{
    delete ui;
}


void PEditor_CCNode::on_doubleSpinBox_x_valueChanged(double  v)
{
    CCNode * node = CCQTSceneDirector::sharedSceneDirector()->CurrentCNode();
    node->setPositionX(v);
	
}

void PEditor_CCNode::on_doubleSpinBox_2_y_valueChanged(double v)
{
    CCNode * node = CCQTSceneDirector::sharedSceneDirector()->CurrentCNode();
    node->setPositionY(v);
}

void PEditor_CCNode::on_doubleSpinBox_3_scaleX_valueChanged(double v)
{
    CCNode * node = CCQTSceneDirector::sharedSceneDirector()->CurrentCNode();
    node->setScaleX(v);
}

void PEditor_CCNode::on_doubleSpinBox_4_scaleY_valueChanged(double v)
{
    CCNode * node = CCQTSceneDirector::sharedSceneDirector()->CurrentCNode();
    node->setScaleY(v);
}

void PEditor_CCNode::on_doubleSpinBox_5_rotate_valueChanged(double v)
{
    CCNode * node = CCQTSceneDirector::sharedSceneDirector()->CurrentCNode();
    node->setRotation(v);
}
